#!/bin/bash

echo "请选择操作类型："
echo "1) 插入新记录"
echo "2) 查询所有记录"
echo "3) 更新指定 ID"
echo "4) 删除指定 ID"
read -p "输入数字 [1-4]: " action
source /home/zhuanghj/app/notifyer/.venv/bin/activate
case $action in
    1)
        echo "插入新记录：请输入以下信息"
        read -p "股票名称 (必填): " stock_name
        read -p "股票代号 (必填): " stock_code
        read -p "市场 (必填，例如 A股/HK/US): " market
        read -p "最高价 (可选): " highest_price
        read -p "最低价 (可选): " lowest_price
        read -p "设置理由 (必填): " reason
        python3 /home/zhuanghj/app/price-checker/stock_manager.py insert \
            --stock_name "$stock_name" \
            --stock_code "$stock_code" \
            --market "$market" \
            --highest_price "$highest_price" \
            --lowest_price "$lowest_price" \
            --reason "$reason"
        ;;
    2)
        echo "查询当前表内容..."
        python3 /home/zhuanghj/app/price-checker/stock_manager.py query
        ;;
    3)
        read -p "请输入要修改的 ID: " stock_id
        echo "输入要修改的字段，如果不修改请留空"
        read -p "股票名称: " stock_name
        read -p "股票代号: " stock_code
        read -p "市场: " market
        read -p "最高价: " highest_price
        read -p "最低价: " lowest_price
        read -p "设置理由: " reason
        python3 /home/zhuanghj/app/price-checker/stock_manager.py update \
            --id "$stock_id" \
            ${stock_name:+--stock_name "$stock_name"} \
            ${stock_code:+--stock_code "$stock_code"} \
            ${market:+--market "$market"} \
            ${highest_price:+--highest_price "$highest_price"} \
            ${lowest_price:+--lowest_price "$lowest_price"} \
            ${reason:+--reason "$reason"}
        ;;
    4)
        read -p "请输入要删除的 ID: " stock_id
        python3 /home/zhuanghj/app/price-checker/stock_manager.py delete --id "$stock_id"
        ;;
    *)
        echo "无效输入，请输入 1~4"
        exit 1
        ;;
esac

deactivate
